<?php 
class CData {

	protected $m_arrmixRequestData;
	protected $m_arrmixPostData;
	protected $m_arrmixGetData;
	protected $m_arrmixSessionData;
	protected $m_arrmixCookieData;
		
	public function __construct() {
		return true;
	}
	
	public function setData() {
		$this->setRequestData( $_REQUEST );
		$this->setPostData( $_POST );
		$this->setGetData( $_GET );
		$this->setSessionData( $_SESSION );	
	}
	
	/**************************************
	************* SET FUNCTIONS ***********
	**************************************/
	
	function setRequestData( $arrmixRequestData ) {
		$this->m_arrmixTempData = array();
		$this->m_arrmixRequestData = $this->assignData( $arrmixRequestData );
	}
	
	function setPostData( $arrmixPostData ) {
		$this->m_arrmixTempData = array();
		$this->m_arrmixPostData = $this->assignData( $arrmixPostData );
	}
	
	function setGetData( $arrmixGetData ) {
		$this->m_arrmixTempData = array();
		$this->m_arrmixGetData = $this->assignData( $arrmixGetData );
	}
	
	function setSessionData( $arrmixSessionData ) {
		$this->m_arrmixTempData = array();
		$this->m_arrmixSessionData = $this->assignData( $arrmixSessionData );
	}
	
	function setCookieData( $arrmixCookieData ) {
		$this->m_arrmixTempData = array();
		$this->m_arrmixCookieData = $this->assignData( $arrmixCookieData );
	}
	
	/**************************************
	************* GET FUNCTIONS ***********
	**************************************/
	
	public function getRequestData( $arrFetchKeys = array(), $arrFetchData = array() ) {
				
		return $this->getFilterData( $this->m_arrmixRequestData, $arrFetchKeys, $arrFetchData );
	}
	
	public function getPostData( $arrFetchKeys = array(), $arrFetchData = array() ) {
	
		return $this->getFilterData( $this->m_arrmixPostData, $arrFetchKeys, $arrFetchData );
	}
	
	public function getGetData( $arrFetchKeys = array(), $arrFetchData = array() ) {
	
		return $this->getFilterData( $this->m_arrmixGetData, $arrFetchKeys, $arrFetchData );
	}
	
	public function getSessionData( $arrFetchKeys = array(), $arrFetchData = array() ) {
	
		return $this->getFilterData( $this->m_arrmixSessionData, $arrFetchKeys, $arrFetchData );
	}
	
	public function getCookieData( $arrFetchKeys = array(), $arrFetchData = array() ) {
	
		return $this->getFilterData( $this->m_arrmixCookieData, $arrFetchKeys, $arrFetchData );
	}
	
	
	/**************************************
	************* OTHER FUNCTIONS ***********
	**************************************/
	
	function assignData( $arrmixData ) {

		if( true == valArr( $arrmixData ) ) {			
			foreach( $arrmixData as $mixKey => $mixValue ) {
				if( true == valArr( $mixValue ) ) {					
					$arrmixTempData[$mixKey] = $this->assignData( $mixValue );
				} else {
					$arrmixTempData[$mixKey] = $this->sanitizeData( $mixValue );
				}			
			}			
		}		
		return ( true == isset( $arrmixTempData ) )?$arrmixTempData:NULL;
	}
	
	function sanitizeData( $mixData ) {
						
		$mixData = trim( $mixData );
		if( 1 == get_magic_quotes_gpc() ) {
			$mixData = stripslashes( $mixData );
		}
		
		$mixData = mysql_real_escape_string( $mixData );
		return $mixData;
	}
	
	function getFilterData( $arrmixData, $arrFetchKeys, $arrFetchData ) {
		$arrFilterData = $arrmixData;
		
		if( true == valArr( $arrmixData ) && true == valArr( $arrFetchKeys ) ) {						
			foreach( $arrFetchKeys as $mixKey ) {			
				if( false == array_key_exists( $mixKey, $arrFilterData ) ) {
					return false;
				}
				$arrFilterData = $arrFilterData[$mixKey];
			}
		}
		
		if( true == valArr( $arrFetchData ) ) {
			$arrFilterData = array_intersect( $arrFilterData, $arrFetchData );
		}
		return $arrFilterData;
	}
}
?>